<extend name="template/base_index" />


<block name="area_header">
	<link rel="stylesheet" type="text/css" media="all" href="__CDN__/jquery-datetimepicker/jquery.datetimepicker.css">
	<script type="text/javascript" src="__CDN__/jquery-datetimepicker/jquery.datetimepicker.js"></script>
	<style type="text/css">
		table{
			border-collapse: collapse;
			border-spacing: 0;
			width:100%;
		}
		table tr{
			height:50px;
			line-height:50px;
			vertical-align: middle;
			width:100%;
		}
		table tr td,table tr th{
			text-align: center;
		}
		table tr:nth-of-type(even){
			border-top: 1px solid #dddddd;
			background:rgb(252,252,252);
		}
	</style>

</block>

<block name="area_body">
	{:W('Menus/topbar')}
	<div class="admin-main container-fluid">
		{:W('Menus/left')}
		<div class="admin-main-content">
			{:W('Menus/breadcrumb')}
		
			<!-- 带验证 form -->
			<form class="form-horizontal well validateForm">
				<input type="hidden" name="product_id" value="{$id}" />
				
				<fieldset>
					<legend>
						商品分组</legend>
					<div class="form-group hide">
						<label for="btns" class="col-md-2 col-lg-2 control-label">&nbsp;</label>
						<div class="col-lg-10 col-md-10">
							<a target-form="validateForm" class="ajax-post btn-sm btn btn-primary" href="{:U('Admin/ProductGroup/add')}" autofocus="autofocus"><i class="fa fa-save"></i> {:L('BTN_SAVE')}</a>
							<a class="btn btn-default btn-sm " href="javascript:window.history.go(-1)"><i class="fa fa-reply"></i>返回</a>
						</div>
					</div>
					<a class="btn btn-primary btn-sm" href="{:U('Admin/Product/addGroup')}">
						<i class="fa fa-plus"></i>
						添加商品分组
					</a>
					<table>
						<tr><th width="60%">分组名称</th><th width="40%">操作</th></tr>
						<volist name="groups" id="vo">
							<tr>
								<td>{$vo.name}</td>
								<td>
									<a href="{:U('Admin/ProductGroup/index',array('id'=>$vo['id']))}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i>管理商品</a>
									<a href="{:U('Admin/Product/deleteGroup',array('id'=>$vo['id']))}"  class="ajax-get btn btn-danger btn-sm confirm" ><i class="fa fa-trash-o"></i>删除</a>
								</td>
							</tr>
						</volist>
					</table>
					<div class="text-muted hide">
                        需要勾选才能生效
                    </div>
               		<div class="form-group hide">
                        <div class="col-md-10 col-lg-10 ">
                            <volist name="groups" id="vo" key="k">
                                <label class="checkbox">
                                    <input type="checkbox" name="groups[]" onclick="getGroupId(this,{$k})"  value="{$vo.id}" <if condition="strpos($addedgroups,$vo['id'].',') === FALSE"><else/>checked="checked"</if> />{$vo.name}

                                    <input name="price_{$vo.id}" class="price input-short" style="font-size: 14px; padding: 5px; border: 1px solid #ccc; border-radius: 5px; color: #999;"
                                    <if condition="!isset($selectedgroups[$vo['id']])">
                                    value="{$product.price}"
                                    <else/> value="{:($selectedgroups[$vo['id']]['price'])}"
                                     </if>

                                            />元(此时的促销价)

                                </label>
                                    <div class="form-group group-time-{$k} well " style=" margin-top: 10px;">
                                        <div class="input-group" style="" >
                                            <div class="input-group-addon" >
                                                时间
                                                <i class="fa fa-calendar"></i>
                                            </div>
                                            <input type="text" name="start_time_{$vo.id}" id="start_time_{$k}" class="startdatetime form-control input-short"
                                                   <if condition="!isset($selectedgroups[$vo['id']])">
                                                       value="{:date('Y-m-d H:i:s',time())}"
                                                       <else/>
                                                       value="{:date('Y-m-d H:i:s',$selectedgroups[$vo['id']]['start_time'])}"
                                                   </if>
                                                    />
                                            <div class="input-group-addon" style="margin-left:20px; float: left; width: 50px;" >
                                                <i class="fa fa-long-arrow-right" style="font-size: 20px;"></i>
                                            </div>
                                            <input type="text" name="end_time_{$vo.id}" id="end_time_{$k}" class="enddatetime form-control input-short"
                                            <if condition="!isset($selectedgroups[$vo['id']])">
                                                value="{:date('Y-m-d H:i:s',time()+24*3600*31)}"
                                                <else/>
                                                value="{:date('Y-m-d H:i:s',$selectedgroups[$vo['id']]['end_time'])}"
                                            </if> />
                                        </div>
                                    </div>
                                    <div class="form-group group-price">

                                    </div>
                            </volist>
                            <div class="help-block">(将商品归类)</div>
                        </div>
                    </div>
					<br/><br/>
					<div class="form-group hide">
						<label for="btns" class="col-md-2 col-lg-2 control-label">&nbsp;</label>
						<div class="col-lg-10 col-md-10">
							<a target-form="validateForm" class="ajax-post btn-sm btn btn-primary" href="{:U('Admin/ProductGroup/add')}" autofocus="autofocus"><i class="fa fa-save"></i> {:L('BTN_SAVE')}</a>

							<a class="btn btn-default btn-sm " href="javascript:window.history.go(-1)"><i class="fa fa-reply"></i>返回</a>
						</div>
					</div>
				</fieldset>
			</form>
			<!-- form -->

		</div>
		<!-- END admin-main-content -->
	</div>
		<!-- END admin-main-->
</block>

<block name="area_footer">

    <script>
        function getGroupId(g,k){
            if(g.checked){
                $(".group-time-"+k).show();
                $(".group-price").show();
            }else{
                $(".group-time-"+k).hide();
                $(".group-price").hide();
            }
        }
        $(function(){
            $(":checked").each(function(){

                if($(this).val()==5999){
                    $(".group-time-4").show();
                    $(".group-price").show();
                }

            });


            $('.startdatetime').datetimepicker({
                lang: 'ch',
                format:'Y-m-d H:i:s',
                timepicker:false,
            });
            $('.enddatetime').datetimepicker({
                lang: 'ch',
                format:'Y-m-d  H:i:s',
                timepicker:false,
            });

            $(".xdsoft_today_button").click();
        });


    </script>
</block>